<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>loadStyleString</title>
</head>

<body>
    <div class="test">字体样式将是#2396ef;</div>
    <script>
        const loadStyleString = code => {
            const style = document.createElement('style');
            style.type = 'text/css';
            try {
                style.appendChild(document.createTextNode(code));
            } catch (ex) {
                style.styleSheet.cssText = code;
            }
            const head = document.getElementsByTagName('head')[0];
            head.appendChild(style);
        };
        loadStyleString('.test { color:#2396ef; }')
    </script>
</body>

</html>